package com.neuedu.yyzx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.entity.ConstantType;
import com.neuedu.yyzx.framework.Res;
import com.neuedu.yyzx.service.IConstantTypeService;
import com.neuedu.yyzx.service.IConstantTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author keyu
 * @since 2024-04-25
 */
@RestController
@RequestMapping("/constantType")
public class ConstantTypeController {
    @Autowired
    IConstantTypeService constantTypeService;
    /**
     * http://localhost:8080/constantType/list
     * @param constantType
     * @return
     */
    @RequestMapping("/list")
    public Res<List<ConstantType>> list(ConstantType constantType) {

        QueryWrapper<ConstantType> queryWrapper = new QueryWrapper<>();
        return Res.ok(constantTypeService.list(queryWrapper));
    }
    //分页查询
    @RequestMapping("/page")
    public Res<Page> page(Page<ConstantType> page, ConstantType constantType) {
        QueryWrapper<ConstantType> queryWrapper = new QueryWrapper<>();
        if(constantType.getType()!= null && !"".equals(constantType.getType().trim())){
            queryWrapper.like("constantTypename" ,constantType.getType() );
        }
        return Res.ok(constantTypeService.page(page,queryWrapper));
    }

    @RequestMapping("/saveOrUpdate")
    public Res  saveOrUpdate( @RequestBody ConstantType constantType){
        return  Res.ok(constantTypeService.saveOrUpdate(constantType));
    }


    @RequestMapping("/removeById/{id}")
    public Res  removeById(@PathVariable int id){
        return  Res.ok(constantTypeService.removeById(id));
    }


    @RequestMapping("/getById/{id}")
    public Res<ConstantType> getById(@PathVariable  int id){
        return  Res.ok(constantTypeService.getById(id));
    }
}
